﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace IntelligentCMS
{
    public partial class manageroles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            CMSDbDataLayer roles = new CMSDbDataLayer(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString, CMSDbDataHelper.Microsoft);
            roles.AddQuery("SELECT [ID], [Name], [Description], [ID] AS [Link] FROM Role");
            roles.SelectQuery = true;
            roles.Execute();

            List<CMSColumnType> newCMSColumnTypes = new List<CMSColumnType>();
            CMSColumnType CMSColumnType_ID = new CMSColumnType(CMSColumnType.CMSCOLUMNTYPE_Text, string.Empty, string.Empty);
            CMSColumnType CMSColumnType_Name = new CMSColumnType(CMSColumnType.CMSCOLUMNTYPE_Text, string.Empty, string.Empty);
            CMSColumnType CMSColumnType_Description = new CMSColumnType(CMSColumnType.CMSCOLUMNTYPE_Text, string.Empty, string.Empty);
            CMSColumnType CMSColumnType_Link = new CMSColumnType(CMSColumnType.CMSCOLUMNTYPE_Hyperlink, "role.aspx?ID={0}", string.Empty);

            newCMSColumnTypes.Add(CMSColumnType_ID);
            newCMSColumnTypes.Add(CMSColumnType_Name);
            newCMSColumnTypes.Add(CMSColumnType_Description);
            newCMSColumnTypes.Add(CMSColumnType_Link);

            for (int i = 0; i < roles.Data.Rows.Count; i++)
            {
                roles.Data.Rows[i]["ID"] = common.FromBase64String(roles.Data.Rows[i]["ID"].ToString());
                roles.Data.Rows[i]["Name"] = common.FromBase64String(roles.Data.Rows[i]["ID"].ToString());
                roles.Data.Rows[i]["Description"] = common.FromBase64String(roles.Data.Rows[i]["ID"].ToString());
                roles.Data.Rows[i]["Link"] = common.FromBase64String(roles.Data.Rows[i]["ID"].ToString());


            }


            //newDataLayer.Data.Columns["Link"].ColumnName = string.Empty;




            theCMSDataGrid.Data = roles.Data;
            theCMSDataGrid.CMSColumnTypes = newCMSColumnTypes;
            theCMSDataGrid.Execute();


        }

        protected void Button_Add_Click(object sender, EventArgs e)
        {
            Response.Redirect("role.aspx");
        }
    }
}
